package string;

import com.seeingtv.common.utils.SafeUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.safehaus.uuid.UUID;
import org.safehaus.uuid.UUIDGenerator;


/**
 * @author hubert
 * @date 2018/4/24
 * @description StringTest2
 */
public class StringTest2 {

	private static String unicodeToCn(String unicode) {
		/** 以 \ u 分割，因为java注释也能识别unicode，因此中间加了一个空格*/
		String[] strs = unicode.split("\\\\u");
		String returnStr = "";
		// 由于unicode字符串以 \ u 开头，因此分割出的第一个字符是""。
		for (int i = 1; i < strs.length; i++) {
			returnStr += (char) Integer.valueOf(strs[i], 16).intValue();
		}
		return returnStr;
	}

	private static String cnToUnicode(String cn) {
		char[] chars = cn.toCharArray();
		String returnStr = "";
		for (int i = 0; i < chars.length; i++) {
			returnStr += "\\u" + Integer.toString(chars[i], 16);
		}
		return returnStr;
	}

	@Test
	public void test() {
		String ftpurl = "ftp://vstor:ero:vsropukka@[fe80::40cc:9497:a11d:a26d%20]/2018/04/13/464546F15DF0C677C7D5C16F1AA5239B.ts";
		String[] values1 = ftpurl.split("//");
		for (int i = 0; i < values1.length; i++) {
			System.out.println("value1="+values1[i]);
		}
		System.out.println("-------------------------------------");
		String [] vlues2 = values1[1].split("@");
		for (int i = 0; i < vlues2.length; i++) {
			System.out.println("value2="+vlues2[i]);
		}
		String username = vlues2[0].split(":")[0];
		String password = vlues2[0].split(":")[1];
	}

	@Test
	public void test2() {
		System.out.println(StringUtils.equalsIgnoreCase("Code1","code"));
	}

	@Test
	public void test3() {
		String pre = "1000800100000501";
		for (int i = 0; i < 100; i++) {
			String fix = SafeUtils.getSqlCurrentTimeStr("yyyyMMddHHmmssSS");
			System.out.println(pre+fix);
		}
	}

	@Test
	public void test4() {
		UUIDGenerator generator = UUIDGenerator.getInstance();
		//基于时间版本
		UUID uuid = generator.generateTimeBasedUUID();
		System.out.println(uuid.toString());

	}

	//&#XX格式转中文
	@Test
	public void test5() {

		String unicode = "&#x4E0B;&#x8F7D;&#x5DE5;&#x5355;XML&#x6587;&#x4EF6;&#x5931;&#x8D25;, &#x539F;&#x56E0;:null";
		System.out.println(StringEscapeUtils.unescapeXml(unicode));
		System.out.println(StringEscapeUtils.unescapeHtml4(unicode));
		System.out.println(StringEscapeUtils.unescapeJava(unicode));
		System.out.println(StringEscapeUtils.unescapeJson(unicode));

		System.out.println(unicodeToCn("\\u4e0e\\u9752\\u6625\\u6709\\u5173\\u7684\\u65e5\\u5b50"));
	}

	@Test
	public void test6() {

	}
}
